package com.alks.function.controller.stockdept.pcfactorystockquery;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.RoleCheck;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.entity.PcLotGroup;
import com.alks.entity.data.entity.PcPackType;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.stockdept.pcfactorystockwork.FinishRecHisRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.FinishRecStoreRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.FinishRecTempRequest;
import com.alks.function.service.stockdept.pcfactorystockquery.IFinishRecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author: chen
 * @date: 2024/11/12
 * @description:
 */
@RestController
@ApiRestController("/finish/rec")
@Api(value = "仓储作业-成品收发", tags = "仓储作业-成品收发")
@Slf4j
@RoleCheck(prgIds = {"160304"})
public class FinishRecController {

    @Resource
    private IFinishRecService service;

    @WebLogger
    @PostMapping("/list")
    @ApiOperation(value = "列表页-按条件分页查询", tags = "仓储作业-成品收发")
    public ResponseInfo finishRecTempQuery(@RequestBody FinishRecTempRequest request) {
        return service.finishRecTempQuery(request);
    }

    @WebLogger
    @PostMapping("/history/list")
    @ApiOperation(value = "明细查询列表页-按条件分页查询", tags = "仓储作业-成品收发")
    public ResponseInfo finishRecHistoryQuery(@RequestBody FinishRecHisRequest request) {
        return service.finishRecHistoryQuery(request);
    }

    @WebLogger
    @PostMapping("/history/del")
    @ApiOperation(value = "删除明细数据", tags = "仓储作业-成品收发")
    public ResponseInfo delRecord(@RequestParam("id") Long id) {
        return service.delRecord(id);
    }

    @WebLogger
    @GetMapping({"/packtype/combo"})
    @ApiOperation(value = "获取装箱方式列表", tags = "仓储作业-成品收发")
    public ResponseInfo<List<PcPackType>> packTypeCombo(String searchKey) {
        return ResponseInfo.ok(service.selectPackTypeCombo(searchKey));
    }

    @WebLogger
    @GetMapping({"/groupno"})
    @ApiOperation(value = "获取配码列表", tags = "仓储作业-成品收发")
    public ResponseInfo groupNos(@RequestParam String lotNo, @RequestParam String collectType) {
        return service.groupNos(lotNo, collectType);
    }

    @WebLogger
    @PostMapping("/stockIn")
    @ApiOperation(value = "提交缴库作业", tags = "仓储作业-成品收发")
    public ResponseInfo stockIn(@Valid @RequestBody FinishRecStoreRequest request) {
        request.setOptType("I");
        return service.updateFinishStore(request);
    }

    @WebLogger
    @PostMapping("/stockOut")
    @ApiOperation(value = "提交出库作业", tags = "仓储作业-成品收发")
    public ResponseInfo stockOut(@Valid @RequestBody FinishRecStoreRequest request) {
        request.setOptType("O");
        return service.updateFinishStore(request);
    }
}
